//
//  SYFileHandle.m
//  BSHOUYIFANG
//
//  Created by lanou3g on 15/8/19.
//  Copyright (c) 2015年 CYB. All rights reserved.
//

#import "SYFileHandle.h"

#import "SYUser.h"
@implementation SYFileHandle

static SYFileHandle * fileHandle = nil;

+ (SYFileHandle *)shareInstance
{
    if (fileHandle ==nil ) {
        fileHandle = [[SYFileHandle alloc] init];
    }
    
    return fileHandle;
}

//同步
- (void)synchronize
{
    [[NSUserDefaults standardUserDefaults]synchronize];
}
- (void)setUserForAll:(SYUser *)user
{
    [[NSUserDefaults standardUserDefaults] setBool:user.isLogin forKey:@"loginState"];
    [[NSUserDefaults standardUserDefaults] setObject:user.phoneNumber forKey:@"phoneNumber"];
    [[NSUserDefaults standardUserDefaults] setObject:user.username forKey:@"username"];
    [[NSUserDefaults standardUserDefaults] setObject:user.password forKey:@"password"];
    [[NSUserDefaults standardUserDefaults] setObject:user.icon forKey:@"icon"];

}
//设置用户信息
- (void)setloginState:(BOOL)isLogin
{
    [[NSUserDefaults standardUserDefaults] setBool:isLogin forKey:@"loginState"];
}

- (void)setPhoneNumber:(NSString *)phoneNumber
{
    [[NSUserDefaults standardUserDefaults] setObject:phoneNumber forKey:@"phoneNumber"];
}

- (void)setUsername:(NSString *)username
{
    [[NSUserDefaults standardUserDefaults] setObject:username forKey:@"username"];
}

- (void)setPassword:(NSString *)password
{
    [[NSUserDefaults standardUserDefaults] setObject:password forKey:@"password"];
}

- (void)setIcon:(NSData *)icon{
    [[NSUserDefaults standardUserDefaults] setObject:icon forKey:@"icon"];
}
//获取用户信息
- (BOOL)loginState
{
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"loginState"];
}

- (NSString *)phoneNumber
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"phoneNumber"];
}

- (NSString *)username
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
}

- (NSString *)password
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];
}

- (NSData *)icon{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"icon"];
}

- (SYUser *)user
{
    SYUser * user = [[SYUser alloc] init];
    user.isLogin = YES;
    user.phoneNumber = [self phoneNumber];
    user.username = [self username];
    user.password = [self password];
    user.icon = [self icon];
    return user;
}


- (void)clearAll{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"phoneNumber"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"username"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"password"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"icon"];
}


#pragma mark ----数据库路径----

@end
